#include "InputDialog.h"

InputDialog::InputDialog(const QString &title, const QString &placeholder, QWidget *parent)
    : QDialog{parent}, textEdit(new QTextEdit(this))
{
    setWindowTitle(title);
    QVBoxLayout *layout = new QVBoxLayout(this);

    QLabel *label = new QLabel(placeholder, this);
    layout->addWidget(label);

    textEdit->setAcceptRichText(false); // 纯文本模式
    textEdit->setPlaceholderText("请输入内容");
    layout->addWidget(textEdit);

    QHBoxLayout *buttonLayout = new QHBoxLayout();
    QPushButton *confirmButton = new QPushButton("确认", this);
    QPushButton *cancelButton = new QPushButton("取消", this);

    connect(confirmButton, &QPushButton::clicked, this, &InputDialog::accept);
    connect(cancelButton, &QPushButton::clicked, this, &InputDialog::reject);

    buttonLayout->addWidget(confirmButton);
    buttonLayout->addWidget(cancelButton);
    layout->addLayout(buttonLayout);

    setMinimumSize(800, 300); // 设置最小窗口大小

    QFont font("微软雅黑", 10);
    this->setFont(font);

    QString confirmStyle = R"(
        QPushButton {
            padding: 8px 16px;
            border-radius: 6px;
            background-color: #4A90E2;
            color: white;
            border: none;
        }
        QPushButton:hover {
            background-color: #357ABD;
        }
    )";

    QString cancelStyle = R"(
        QPushButton {
            padding: 8px 16px;
            border-radius: 6px;
            background-color: #9E9E9E;
            color: white;
            border: none;
        }
        QPushButton:hover {
            background-color: #616161;
        }
    )";

    confirmButton->setStyleSheet(confirmStyle);
    cancelButton->setStyleSheet(cancelStyle);

    // 文本编辑框样式
    textEdit->setStyleSheet(R"(
        QTextEdit {
            padding: 8px;
            border: 1px solid #CCCCCC;
            border-radius: 4px;
            font-size: 14px;
        }
    )");

    // 对话框背景色
    this->setStyleSheet("QDialog { background-color: #F9F9F9; }");
}

QString InputDialog::getInputText() const
{
    return textEdit->toPlainText();
}